package binary_tree.Newcode;

//import java.util.Hashtable;
//import java.util.Scanner;

import java.util.Scanner;

public class chufang {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a=0,b=1,c=1;
        while(c<n){
            a=b;
            b=c;
            c=a+b;
        }
        int n1=n-b;
        int n2=c-n;
        System.out.println(n1<n2?n1:n2);
    }
//    public static void main(String[] args) {
//        Scanner sc=new Scanner(System.in);
//        Hashtable<String,Integer> set=new Hashtable<String,Integer>();
//        while(sc.hasNext()){
//            String str=sc.next();
//            set.put(str,1);
//        }
//        System.out.println(set.size());
//    }
}
